<template>
  <el-card>
    <el-row slot="header" type="flex" justify="space-between">
      <h4>跨区域转货申请单-查看</h4>
      <el-button size="mini" type="primary" :loading="exportLoading" @click="handleExport">导出明细</el-button>
    </el-row>
    <el-row>
      <skus-table
        :table-height="500"
        :data-source="tableInfo.list"
        :loading="tableInfo.loading"
        :columns="tableInfo.columns"
      />
    </el-row>
    <FooterFields :footerFields="viewdata" />
  </el-card>
</template>

<script>
import FooterFields from '@/pages/commodity/components/FooterFields';
import SkusTable from '@/components/skusTable';
import { queryTransferDetailService, transferGoodsExportService } from '@api/stock/stockOverflow';
import { VIEW_TABLE_COLUMNS } from './constants';
import { createExcelByExport } from '@/utils/bizUtils';

export default {
  components: {
    FooterFields,
    SkusTable
  },
  data () {
    return {
      tableInfo: {
        list: [],
        columns: VIEW_TABLE_COLUMNS,
        loading: false
      },
      recordNo: '',
      viewdata: {},
      exportLoading: false
    };
  },
  created () {
    this.recordNo = this.$route.query.recordNo;
    this.getTableData();
  },
  methods: {
    async getTableData () {
      const res = await queryTransferDetailService({ recordNo: this.recordNo }, state => { this.tableInfo.loading = state })
      if (res?.retData) {
        const { detailList, recordInfo } = res.retData;
        this.tableInfo.list = detailList;
        this.viewdata = recordInfo;
      }
    },
    async handleExport () {
      const res = await transferGoodsExportService({ recordNo: this.recordNo }, state => { this.exportLoading = state })
      if (res) {
        createExcelByExport({ res, excelTitle: '跨区域转货申请单' });
      }
    }
  }
};
</script>
